<?php
//这是公用入口模块
class main extends spController
{
	function __construct(){ // 公用
		parent::__construct(); // 这是必须的
		$this->tpl_title = "蓝田创立网站监控系统";
	}
	
	function index(){ // 这里是首页
		$this->display("index/main_index.html");
	}
	
	function page(){ // 其他内容
		echo "wewfwefwe";
		$this->display("index/main_page.html");
	}
	
	function login()
	{		
		$userObj = spClass("user");
		if( $username = $this->spArgs("username") ){
			$password = $this->spArgs("password");
			$rows = array
			(
				'username' => $username, 
				'password' => $password
			);
			$results = $userObj->spVerifier($rows);
			
			if( false == $results ){ 
				if( false == $userObj->userlogin($username, $password) ){
					$this->error("用户名/密码错误，请重新输入！", spUrl("main","index"));
					
				}else{
					$useracl = spClass("spAcl")->get(); 
					if( "GBADMIN" == $useracl ){
						$user=spClass('user');
						$data['lasttime']=strtotime(date("Y-m-d H:i:s"));
						$where ['userid'] = $_SESSION["userinfo"]["userid"];
						$user->update ( $where, $data );
						$this->success("登录成功，欢迎您，管理员！", "member.php?c=main&a=site");		
					}else{
						$this->success("登录成功，欢迎您，尊敬的会员！", "member.php?c=main&a=site");
					}
				}
			}else{
				foreach($results as $item){
					foreach($item as $msg){ 
						$this->error($msg,spUrl("main","index"));
					}
				}
			}
		}
		else 
		{
			$url = spUrl("main","index");
			echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
				<script>function sptips(){alert(\"请输入用户名和密码！\");location.href=\"{$url}\";}</script>
				</head><body onload=\"sptips()\"></body></html>";
			exit;
		}
	}
	
	// 退出登录
	 function logout()
	 {
		$_SESSION = array();
		if (isset($_COOKIE[session_name()])) {setcookie(session_name(), '', time()-42000, '/');}
		spClass('spAcl')->set("");
		session_destroy();
		$this->success("已退出，返回首页！", spUrl("main","index"));
	}
	function sc()
	{
		echo '成功';
	}
	
	function zhuce()
	{
		$this->contents = "这是注册页面";
		$this->display("index/main_registered.html");		
	}
	//注册
	function registered()
	{		
		$data = $this->spArgs();
		$data[acl] = 'GBUSER'; 
		$data['addtime']=strtotime(date("Y-m-d H:i:s"));
		$data['lasttime']=strtotime(date("Y-m-d H:i:s"));
		$data['password']=md5($this->spArgs('password'));
		$data['status']=60;
		$user['username'] = $this->spArgs('username');
		
		$Model = spClass('user');
		
		$rows = array
		(
			'username' => $this->spArgs('username'), 
			'password' => $this->spArgs('password'),
		);
		$results = $Model->spVerifier($rows);
		if( false == $results )
		{
			if($rs = $Model->find($user))
			{
				$this->error("用户已存在！",spUrl("main","zhuce"));
			}
			else{	
				if($Model->create($data))
        		{          	
          			$this->success("注册成功，欢迎您的加入", spUrl("main","index"));
        		}
			}
		}
		else
		{
			foreach($results as $item)
			{
				foreach($item as $msg)
				{
					$this->error($msg,spUrl("main","zhuce"));
				}
			}
		}        
	}
	
	
	
	
	
	//lj
}	